<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<div id="dialog-message">
	 	<table class="table table-striped table-hover table-bordered">
	 			<thead>
			 		<tr>
			 			<th width='130px'>时间</th><th week='1'>周一</th><th  week='2'>周二</th><th  week='3'>周三</th><th  week='4'>周四</th><th  week='5'>周五</th><th  week='6'>周六</th><th  week='7'>周日</th>
			 		</tr>
		 		</thead>
		 	 <tbody id="showPlant_tableBody">
		 	 
		 	 </tbody>
		 </table>
</div>
<script type="text/javascript">
(function(){
	var teacherId = "${param.table_id}";
	var userType="${param.userType}"; 
	//加载课表
 	function loadClassPlant(){
		
 		var url ="${pageContext.request.contextPath}/edu/sys_ClassPlantAction.do?method=getTeacherPlantMaster";
		if(userType=="1"){
			url ="${pageContext.request.contextPath}/edu/sys_ClassPlantAction.do?method=getStudentPlantMaster";
		}
 		$.ajax({
			   type: "POST",
			   url: url,
			   async:false,
			   dataType:'json',
			   data: {table_id:teacherId},
			   success: function(msg){  
			      if(msg && msg.list && msg.list[0]!=null){ 
			    	  showMsg(msg);
			      }
			   }
		});
 	};
 	//显示课表
 	function  showMsg(msg){
 		 
 		var arr = new Array(); 
 		//这个循环是为了去掉重复的时间问题
		 for(var i=0;i<msg.list.length;i++){
			 var b =false;
			 for(var j=0;j<arr.length;j++){
				 if(arr[j].start1 ==msg.list[i].start1 && arr[j].end == msg.list[i].end){
					b=true;
					break;
				 }
			 }
			 if(b==false){
				 arr.push(msg.list[i]);
				// alert(msg.list[i].start1 +"=="+msg.list[i].end);
			 }
		 }  
 		 //按左边的时间，找到对应的课表，显示
 		 for(var i=0;i<arr.length;i++){ 
    		 var tbody =$("#showPlant_tableBody");
    		 var kbit1 = arr[i];
    		 var tr =$('<tr></tr>');
    		 var td0 =$("<td>"+ kbit1.start1+"--"+ kbit1.end+"</td>");
			 var td1 =$("<td week='1'></td>");
			 var td2 =$("<td week='2'></td>");
			 var td3 =$("<td week='3'></td>");
			 var td4 =$("<td week='4'></td>");
			 var td5 =$("<td week='5'></td>");
			 var td6 =$("<td week='6'></td>");
			 var td7 =$("<td week='7'></td>");
    		 for(var j=0;j<msg.list.length;j++){  
    			 var kbit2 = msg.list[j];
    			 if(kbit2.start1 == kbit1.start1 && kbit2.end == kbit1.end){
    				  if(kbit2.week ==1){
    					  td1.text(kbit2.sname);
    				  } 
    				  if(kbit2.week ==2){
    					  td2.text(kbit2.sname);
    				  } 
    				  if(kbit2.week ==3){
    					  td3.text(kbit2.sname);
    				  } 
    				  if(kbit2.week ==4){
    					  td4.text(kbit2.sname);
    				  } 
    				  if(kbit2.week ==5){
    					  td5.text(kbit2.sname);
    				  } 
    				  if(kbit2.week ==6){
    					  td6.text(kbit2.sname);
    				  } 
    				  if(kbit2.week ==7){
    					  td7.text(kbit2.sname);
    				  }  
    			 } 
    		 }
    		 tr.append(td0);tr.append(td1); tr.append(td2); tr.append(td3); tr.append(td4); tr.append(td5); tr.append(td6); tr.append(td7);
   		 	 tbody.append(tr);
    		
    	 }   
 	}
	$(function(){
		if(teacherId!=""){
			loadClassPlant();
		}
	});
})();
</script>